package com.itbac.mybatisplusspringbootdemo.injector.methods;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * 查询一条数据，不会抛异常
 */
public class getLimitOne extends AbstractMethod {
    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        SqlSource sqlSource = this.languageDriver.createSqlSource(this.configuration,
                String.format(MySqlMethod.GET_LIMIT_ONE.getSql(), this.sqlSelectColumns(tableInfo, true),
                        tableInfo.getTableName(),
                        this.sqlWhereEntityWrapper(true, tableInfo)), modelClass);
        return this.addSelectMappedStatement(mapperClass, "getLimitOne", sqlSource, modelClass, tableInfo);

    }
}
